package com.catsic.pub.convert;

import com.catsic.base.tree.TreeInfo;
import com.catsic.pub.entity.Drawer;
import com.catsic.pub.entity.Xzqh;
import com.catsic.pub.form.DrawerForm;
import com.catsic.pub.form.XzqhForm;
/**
 * 转换类
 * @author yangyudi
 *
 */
public class Converts{

	/**
	 * 赋值TreeInfo
	 * @author yangyd
	 * @date 2014-8-7 
	 * @param 
	 * @return
	 */
	public static TreeInfo convertTree(Drawer drawer){  
		TreeInfo treeInfo = new TreeInfo();
		treeInfo.setId(drawer.getId());
		treeInfo.setCode(drawer.getCode());
		treeInfo.setName(drawer.getName());
		treeInfo.setPid(drawer.getParent() == null ? null : drawer.getParent().getId());
		return treeInfo;
	}
	
	/**
	 * 赋值DrawerForm
	 * @author yangyd
	 * @date 2014-8-7 
	 * @param 
	 * @return
	 */
	public static DrawerForm convert(Drawer drawer){  
		DrawerForm drawerForm = new DrawerForm();
		drawerForm.setId(drawer.getId());
		drawerForm.setCode(drawer.getCode());
		if(drawer.getParent() != null){
			drawerForm.setPid(drawer.getParent().getId());
		}
		drawerForm.setName(drawer.getName());
		drawerForm.setValue(drawer.getValue());
		drawerForm.setStatus(drawer.getStatus());
		return drawerForm;
	}
	
	
	/**
	 * 转换为XzqhForm
	 * @return
	 */
	public static XzqhForm convert(Xzqh xzqh) {
		XzqhForm form = new XzqhForm();
		form.setId(xzqh.getId());
		if(xzqh.getParent() != null){
			form.setPid(xzqh.getParent().getId());
		}
		form.setName(xzqh.getName());
		return form;
	}
}
